package com.example.myapplication.tack_14;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_14.data.Classification02Data;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import okhttp3.Request;

public class NewsFenLeiPageActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView image;
    private TextView guide;
    private TextView  introduce;
    private Intent intent;
    private String sort;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_14_activity_news_fen_lei_page);
        init();
        intent = getIntent();
        sort = intent.getStringExtra(Common.COMMON);
        exit_();
        getPage(sort);
    }

    private void getPage(String sort) {
        String url ="prod-api/api/garbage-classification/garbage-classification/list?sort="+sort;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, Classification02Data.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                Classification02Data classification02Data = (Classification02Data)obj;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(classification02Data.getCode() == 200){
                            Glide.with(NewsFenLeiPageActivity.this).load(OkHttpTool.URL+classification02Data.getRows().get(0).getImgUrl()).into(image);
                            guide.setText(classification02Data.getRows().get(0).getGuide());
                            introduce.setText(classification02Data.getRows().get(0).getIntroduce());
                        }
                    }
                });

            }

            @Override
            public void onFailure(String msg) {

            }
        });

    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsFenLeiPageActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        image = findViewById(R.id.imags);
        guide = findViewById(R.id.guide);
        introduce = findViewById(R.id.introduce);
    }
}